#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
typedef struct
{
    int shuLiang;
    int rmb;
} qian;
int n;
int sswap(qian p)
{
    int sum = 0;
    int ss = 0;
    while (sum < n)
    {
        sum += p.shuLiang;
        ss += p.rmb;
    }
    return ss;
}
int main()
{
    cin >> n;
    qian a[3];
    int s[3];
    for (int i = 0; i <= 2; i++)
    {
        cin >> a[i].shuLiang >> a[i].rmb;
        s[i] = sswap(a[i]);
    }
    sort(s, s + 3);
    cout << s[0];
}